<?php
header("Content-type:text/xml;charset=utf-8");
global $wpdb;
$first=intval($_REQUEST["first"]);
$last=intval($_REQUEST["last"]);

$firstlim=($first<=1)?0:($first-1);


$lastlim=($last<1)?0:$last;
	$sql_total="select count(*) from miao_photo where  flag=1 ";;
	$total=$wpdb->get_var($sql_total);
echo "<?xml version='1.0' encoding='UTF-8'?>";
echo "<root>";	
echo "<total>$total</total>";	
	$sql_works="select * from miao_photo where  flag=1 order by id desc limit $firstlim ,$lastlim";
	
	//echo $sql_works;
	
	$results_works=$wpdb->get_results($sql_works);
	if($results_works!=NULL){
	
	
	foreach($results_works as $v){
		 $works_title=$v->title;
		 $imgpath=$v->imgpath;
	echo "<data>";	
		echo "<image>$imgpath</image>";
		echo "<title>$works_title</title>";
 echo "</data>"; 
	}	 
	}
echo "</root>";
?>